﻿@using Newtonsoft.Json
@using BlockMain_Class
@{
    Layout = "/Views/Shared/_Layout.cshtml";
    var model = (Publiclist)Model;
}
<link rel="stylesheet" type="text/css" href="/assets/Css/PublicIndex.css" />
<body>
    <div class="bgimg">
        <div class="left">
            <div class="logo"></div>
        </div>
        <div class="right">
            @*<div class="top">
                    <div class="user">
                        <img class="user-img" src="/Assets/Images/touxiang.png" />
                        <span class="txt">欢迎登陆</span>
                    </div>
                    <div class="checkout">
                        <img class="checkout-img" src="/Assets/Images/fytuichu.png" />
                        <span class="txt">退出</span>
                    </div>
                </div>*@
            <div class="middle">
                <div class="contant">
                    <div class="title">
                        公链展示
                    </div>
                    <div class="inform">
                        <div class="informleft">
                            <div class="pre">
                                <img src="/Assets/Images/lianjie.png" />
                                <span>当前节点数：@(model.peernum)</span>
                            </div>
                            <div class="after">
                                <img src="/Assets/Images/gaodu.png" />
                                <span>区块高度：@(model.height.ToString("#,##0"))</span>
                            </div>
                        </div>
                        <div class="informright">
                            <div class="submit" onclick="SelectList()" style="display: inline-block">
                                查询
                            </div>
                            <div class="submit" onclick="UpChain()" style="display: inline-block">
                                上链
                            </div>
                        </div>
                    </div>
                    <div class="table-1">
                        <table border="" cellspacing="" cellpadding="">
                            @*<tr>
                                    <th colspan="6">节点</th>
                                </tr>*@
                            <tr>
                                <th style="text-align: center">
                                    序号
                                </th>
                                <th>
                                    节点名称
                                </th>
                                <th>
                                    状态
                                </th>
                                <th>
                                    区块高度
                                </th>
                                <th>
                                    当前区块哈希值
                                </th>
                                <th>
                                    最新区块时间
                                </th>
                                <th>
                                    操作
                                </th>
                            </tr>
                            @foreach (var item in model.PeerList)
                            {
                                <tr>
                                    <td>
                                        @item.No
                                    </td>
                                    <td>
                                        @item.Name
                                    </td>
                                    <td>
                                        @if (item.state == 0)
                                        {
                                            <img src="/Assets/Images/wuxianzhi.png" />
                                        }
                                        @(item.state == 0 ? "数据已同步" : "数据未同步")
                                    </td>
                                    <td>
                                        @item.height.ToString("#,##0")
                                    </td>
                                    <td>
                                        @HashReplace.get(item.nowhash)
                                    </td>
                                    <td>
                                        @item.addtime
                                    </td>
                                    <td>
                                        <a href="/Show/PeerSelect?Id=@(item.Id)">详情</a>
                                    </td>
                                </tr>
                            }


                        </table>
                    </div>
                    <div class="table-1">
                        <table border="" cellspacing="" cellpadding="">
                            <tr>
                                <th colspan="6">最新上链</th>
                            </tr>
                            <tr>
                                <th style="text-align: center">
                                    区块高度
                                </th>
                                <th>
                                    当前区块哈希值
                                </th>
                                <th>
                                    交易发起方
                                </th>
                                <th>
                                    交易接收方
                                </th>
                                <th>
                                    入链时间
                                </th>
                                <th>
                                    操作
                                </th>
                            </tr>

                            @foreach (var item in model.BlockchainList)
                            {
                                <tr>
                                    <td>
                                        @item.Height.ToString("#,##0")
                                    </td>
                                    <td>
                                        @HashReplace.get(item.Hash ?? "...")
                                        @*<button onclick="">复制</button>*@
                                    </td>
                                    <td>
                                        @try
                                        {
                                            //处理调试数据
                                            var jsondata = JsonConvert.DeserializeObject<UserRecordJson>(item.Data);
                                            @(jsondata.Mechanism)
                                        }
                                        catch
                                        {
                                            @*@("欢迎你光临我的联盟链..")*@
                                        }
                                    </td>
                                    <td>
                                        @try
                                        {
                                            //处理调试数据
                                            var jsondata = JsonConvert.DeserializeObject<UserRecordJson>(item.Data);
                                            @(jsondata.TestMechanism)
                                        }
                                        catch
                                        {
                                            @*@("创世链无上一区块")*@
                                        }
                                    </td>
                                    <td>
                                        @ToDate.To(item.TimeStamp).ToString("yyyy-MM-dd HH:mm:ss")
                                    </td>
                                    <td>
                                        <a href="/Show/Select?hash=@(item.Hash)">详情</a>
                                    </td>
                                </tr>
                            }

                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>


<script>

    window.setInterval(function () {
        GetNew();
    }, 60000);


    //获取最新数据
    function GetNew() {
        $.ajax({
            type: "POST",
            url: "/Public/GetNew",
            dataType: "json",
            success: function (msg) {
                //处理json
                console.log(msg);
            }
        });
    }

    //上联
    function UpChain() {
        window.location.href = "/Show";
    }
    //查询
    function SelectList() {
        window.location.href = "/Show/List";
    }
</script>
<script type="text/javascript">
    $(function () {
        var haxi = "0000f727854b50bb95c054b39c1fe5c92e5ebcfa4bcb5dc279f56aa96a365e5a"
        var newhaxi = haxi.slice(0, 6) + "..."
        console.log(newhaxi)
        $(".haxi").text(newhaxi)
    })
</script>